<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>">
<title>激活卡作废</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp"%>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<style>
.h_30 {
	height: 30px;
}

.table_body_div {
	padding: 10px 15%;
}

.table_date {
	padding: 20px 0 20px 30%;
}

#date {
	margin-left: 10%;
}

.calendars {
	z-index: 10001;
}

.fr {
	float: right;
}

.fl {
	float: left;
}

.w_50 {
	width: 50%;
}
/* 清除浮动 */
.clear::after {
	clear:both;
	content:'.';
	display:block;
	width: 0;
	height: 0;
	visibility:hidden;
}/*==for FF/chrome/opera/IE8==*/
</style>
<script type="text/javascript">
	/* 初始化 start */
	$(function() {
		queryCardInfo(1)
	})
	/* 初始化 end */
	/* 查询卡库存   start */
	function queryCardInfo(displayPage){
 		var name= $("#name").val();
		var startNo=$("#startNo").val();
		var endNo=$("#endNo").val();
		loadCardData({current:displayPage,size:10,cardDefineName: name,startNo:startNo,endNo:endNo}); 
	}
	function loadCardData(param){
		var jsonDate;
		if(null != param && null != param.current){
			jsonDate =param;	
		}else{
			jsonDate={current:1,size:10};
		}
		$.openLoading();
 		$.ajax({
			url : "cancelCard/queryStock",
			type : 'POST',
			async : true,
			dataType:'json',
			data: param,
			success : function(page) {
				$.closeLoading();
				if($.validate(page))return;
				var radioObj ="<input class='input_fxk' name='checkBoxCard' type='checkbox' value=''>";
				var fieldNames = "cardDefineId@TDH,name,pricelessType?{0:'有价';1:'非有价'},cardNo,deptName,status?{0: '库存'; '1': '上交'; '2': '下发'; '3': '关联销售信息'; '4': '可激活/已缴费'; '5': '已激活'; '6': '作废'; '7': '锁定'},totPremamt,disableDateStr";
				var tableContent = creatTable4(fieldNames, page, radioObj);
				var tableObj = $("#cardpageTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage(page.current,6,page.maxPage,"75");
				var pageDIV = $("#cardpageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				bindradio();//点击单选按钮，该行高亮显示
			}
		}) 
	}
	/* 查询卡库存   end */
	/* 作废 start */
	function cancel() {
		if ($("input[name='checkBoxCard']:checked").length <= 0) {
			$.message("error", "请至少选择一张卡作废！");
			return
		}
		var cardDefineIdList = $.map($("input[name='checkBoxCard']:checked").parent().next(), function (v, i) {
			return $(v).html();
		});
		var cardNoList = $.map($("input[name='checkBoxCard']:checked").parent().next().next().next().next(), function (v, i) {
			return $(v).html();
		});
		var param = {cardDefineIdList: cardDefineIdList,cardNoList:cardNoList};
		$.openLoading();
 		$.ajax({
			url : "cancelCard/cardCancelList",
			type : 'POST',
			async : true,
			dataType:'json',
			data: param,
			traditional :true,  //注意这个参数是必须的
			success : function(data) {
				$.closeLoading();
				if("success"==data.result&&""!=data.message){
					$.message("success", data.message);
					queryCardInfo($('.page_a_click').html())//重新查询当前页面
		    	}
				if("fail"==data.result){
		    		$.message("error", "系统错误,请联系管理员");
		    	}
				if("error"==data.result&&""!=data.message){
		    		$.message("error", data.message);
		    	}
			}
		}) 
		
	}
	/* 作废 end */
	/* 批量作废 start */
	function cardCancelBatch() {
		var startNo = $('#mStartNo').val();
		var endNo = $('#mEndNo').val();
		var cardDefineId=$('#mCardDefineId').val();
		if (!startNo) {
			$.message("error", "请填写开始卡号！ ");
			return
		} else if (!endNo) {
			$.message("error", "请填写结束卡号！ ");
			return
		}
		var param = {cardDefineId:cardDefineId,startNo: startNo, endNo: endNo}
		$.openLoading();
 		$.ajax({
			url : "cancelCard/cardCancelBatch",
			type : 'POST',
			async : true,
			dataType:'json',
			data: param,
			success : function(data) {
				$.closeLoading();
				if("success"==data.result&&""!=data.message){
					$.message("success", data.message);
					cancelDivClose()
					queryCardInfo($('.page_a_click').html())//重新查询当前页面
		    	}
				if("fail"==data.result){
		    		$.message("error", "系统错误,请联系管理员");
		    	}
				if("error"==data.result&&""!=data.message){
		    		$.message("error", data.message);
		    	}
			}
		}) 
		
	}
	/* 批量作废 end */
	/* 打开批量弹窗 start */
	function cancelDivOpen() {
		if ($("input[name='checkBoxCard']:checked").length <= 0) {
			$.message("error", "请选择一条卡作废！");
			return
		}
		if ($("input[name='checkBoxCard']:checked").length >1) {
			$.message("error", "请选择一条卡作废！");
			return
		}
		var checkBox=$("input[name='checkBoxCard']:checked");
		var cardDefineId = checkBox.parent().next().html();
		var name = checkBox.parent().next().next().html();
		var cardNo = checkBox.parent().next().next().next().next().html();
		$("#mName").html(name);
		$("#mStartNo").val(cardNo);
		$("#mCardDefineId").val(cardDefineId);
		$('#cancelDiv').OpenDiv();
	}
	/*作废统计页面*/
	function countOpen(){
		window.location.href='<%=path%>/cancelCard/countCancel';
	}
	
	/* 打开批量弹窗 end */
	/* 关闭批量弹窗  start */
	function cancelDivClose() {
		$('#mStartNo').val('');
		$('#mEndNo').val('');
		$('#mName').html('');
		$("#mCardDefineId").val('');
		closeCurrentDIV('cancelDiv');
	}
	/* 关闭批量弹窗  end */
	/* 多选按钮高亮 start */
    function bindradio(){
		$("input[name='checkBoxCard']").click(function(){
			$("input[name='checkBoxCard']").parent().parent().removeClass("table_highlighter");
			$("input[name='checkBoxCard']:checked").parent().parent().addClass("table_highlighter");
	   	});
    }
    /* 多选按钮高亮 end */
	// 统一 关闭  窗口
	function closeCurrentDIV(obj){
		$("#"+obj).CloseDiv();
	}
	/*重置*/
	function vreset(){
		$("#name").val("");
		$("#startNo").val("");
		$("#endNo").val("");
	}
	</script>
</head>
<body>
	<div class="current">
		<table class="current_table_1">
			<tbody>
				<tr class="f2">
					<td><img src="./images/current_1.jpg"></td>
					<td class="current_table_1_td"><img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
						<span style="color: #136bab;">激活卡管理 <span
							style="padding: 0 5px; font-weight: bold; line-height: 28px;">&gt;</span>
							激活卡作废
					</span></td>
					<td><img src="./images/current_3.jpg"></td>
				</tr>
			</tbody>
		</table>
	</div>

	<table class="table_02" id="table">
		<tr>
			<td>
				<table class="search_table">
					<tr height="30px">
						<td width="25%" height="30">卡定义名称： <input name="name"
							id="name" type="text" class="input_text" maxlength="30" value="">
						</td>
						<td width="25%" height="30">开始卡号： <input name="startNo"
							id="startNo" type="text" class="input_text" maxlength="30" value="" onkeyup="this.value=this.value.replace(/\D/g, '')">
						</td>
						<td width="25%" height="30">结束卡号： <input name="endNo"
							id="endNo" type="text" class="input_text" maxlength="30" value="" onkeyup="this.value=this.value.replace(/\D/g, '')">
						</td>
						
					</tr>
					<tr>
					   <td height="30" colspan="4" style="text-align: center;">
                            <input type="button" class="input_button_1" id="searchBtn" value="查询" onClick="queryCardInfo(1)" />
                            &nbsp;&nbsp;<input type="button" class="input_button_1" id="searchBtn" value="重置" onclick="vreset()" /></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="search_table">
					<tr height="30px">
						<td width="30%" height="30">
							<input type="button"
								class="input_button_1" value="作废"
								onClick="cancel()" /> 
							&nbsp;<input type="button"
								class="input_button_2" value="批量作废"
								onClick="cancelDivOpen()" />
							&nbsp;<input type="button"
								class="input_button_2" value="作废统计"
								onClick="countOpen()" />
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<!-- 数据列表 start -->
		<tr>
			<td>
				<table id="cardpageTable" class="content_table_1">
					<thead>
						<tr class="f1">
							<th style="width: 5%;">选择</th>
							<th style="width: 18%;">卡定义名称</th>
							<th style="width: 9%;">卡类型</th>
							<th style="width: 15%;">卡号</th>
							<th style="width: 26%;">所属机构</th>
							<th style="width: 9%;">卡状态</th>
							<th style="width: 9%;">保费</th>
							<th style="width: 9%;">失效日期</th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
				<div id="cardpageDIV" class="page"></div>
			</td>
		</tr>
		<!-- 数据列表 end -->
	</table>
	<!-- 批量作废 start -->
	<div id="cancelDiv" style="display: none; width:  60%;">	
		<input type="hidden" id="mCardDefineId" name="mCardDefineId" />
		<div class="table_title_div">
			<table class="table_title" style='width: 100%; height: 20px;'>
				<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img
						src="./images/closedown.gif" alt="关闭" onclick="cancelDivClose()" /></td>
				</tr>
			</table>
		</div>
		<div class="table_body_div">
		    <div class="table_num clear">
		    	<H2>卡定义名称：<span id="mName"></span></H2>
		    </div>
		    <br>
			<div class="table_num clear">
				<div class="fl w_50 h_30">
					<span>开始卡号</span> 
					<input name="mstartNo" id="mStartNo" type="text" class="input_text" maxlength="30" value="" onkeyup="this.value=this.value.replace(/\D/g, '')">
				</div>
				<div class="fr w_50">
					<span>结束卡号</span> 
					<input name="mendNo" id="mEndNo" type="text" class="input_text" maxlength="30" value="" onkeyup="this.value=this.value.replace(/\D/g, '')">
				</div>
			</div>
		</div>
		<div align="center">
			<input class="input_button_3" type="button" onclick="cardCancelBatch()" value="作废">&nbsp;&nbsp; 
			<input class="input_button_3" type="button" onclick="cancelDivClose()" value="取消">
		</div>
	</div>
	<!-- 批量作废 end -->
	<div id="Loading" style="display: none" align="center">
		<img src="./images/loading.gif" />
	</div>
</body>
</html>